import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import watchFolderPlugin from './generateApi'

const pathResolve = (dir: string) => resolve(__dirname, '.', dir)

export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({ dirs: ['src/service/modules'] }),
    watchFolderPlugin({
      fileName: pathResolve('src/service/Api.d.ts'),
      folderName: pathResolve('src/service/modules'),
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  css: {
    postcss: {
      plugins: [require('tailwindcss'), require('autoprefixer')],
    },
  },
  base: '/',
  server: {
    cors: true,
    host: '0.0.0.0',
    port: 8005,
    strictPort: true,
  },
})
